package com.ruoyi.audit.controller;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.audit.domain.Audit;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.audit.service.IAuditService;
import com.ruoyi.common.core.page.TableDataInfo;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

/**
 * 财务审核Controller
 * 
 * @author ruoyi
 * @date 2024-05-12
 */
@RestController
@RequestMapping("/audit/audit")
public class AuditController extends BaseController
{
    @Autowired
    private IAuditService auditService;

    /**
     * 审核并转账
     * @param id
     */
    @PreAuthorize("@ss.hasPermi('audit:audit:check')")
    @GetMapping(value = "/check/{id}")
    public void check(@PathVariable("id") Long id)
    {
        auditService.LookWithdrawStatus(id);
    }

    /**
     * 财务拒绝
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('audit:audit:refuse')")
    @GetMapping(value = "/refuse/{id}")
    public void refuse(@PathVariable("id") Long id)
    {
         auditService.updateWithdrawStatus(id);
    }


    /**
     * 查询财务审核列表
     */
    @PreAuthorize("@ss.hasPermi('audit:audit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Audit audit)
    {
        startPage();
        List<Audit> list = auditService.selectAuditList(audit);
        return getDataTable(list);
    }

    /**
     * 导出财务审核列表
     */
    @PreAuthorize("@ss.hasPermi('audit:audit:export')")
    @Log(title = "财务审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Audit audit)
    {
        List<Audit> list = auditService.selectAuditList(audit);
        ExcelUtil<Audit> util = new ExcelUtil<Audit>(Audit.class);
        util.exportExcel(response, list, "财务审核数据");
    }

    /**
     * 获取财务审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('audit:audit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(auditService.selectAuditById(id));
    }

    /**
     * 新增财务审核
     */
    @PreAuthorize("@ss.hasPermi('audit:audit:add')")
    @Log(title = "财务审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Audit audit)
    {
        return toAjax(auditService.insertAudit(audit));
    }

    /**
     * 修改财务审核
     */
    @PreAuthorize("@ss.hasPermi('audit:audit:edit')")
    @Log(title = "财务审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Audit audit)
    {
        return toAjax(auditService.updateAudit(audit));
    }

    /**
     * 删除财务审核
     */
    @PreAuthorize("@ss.hasPermi('audit:audit:remove')")
    @Log(title = "财务审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(auditService.deleteAuditByIds(ids));
    }
}
